<!--待审批账单自定义操作-->
<template>
  <el-dropdown @command="handleCommand">
    <span class="el-dropdown-link">
      更多<i class="el-icon-arrow-down el-icon--right"></i>
    </span>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item :command="review">审核账单</el-dropdown-item>
      <el-dropdown-item :command="writeoff">标记销账</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";

export default {
  props: ["data"],
  data() {
    return {
      review: "",
      writeoff: ""
    };
  },
  created() {},
  mounted() {
    this.review = "review_" + this.data.id;
    this.writeoff = "writeoff_" + this.data.id;
  },
  methods: {
    handleCommand(command) {
      // 当前操作ID
      const id = command.split("_")[1];
      // 待审批账单
      if (command.indexOf("review_") > -1) {
        // 新页面打开
        window.open("/#/blank/finance__account__main?customerBillIdStrs=" + id);
      } else if (command.indexOf("writeoff_") > -1) {
        this.$confirm("确定执行此操作么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            // 标记为已销账
            const row = [];
            row.push(id);
            ajax("remarkSaleBillCrossOf", row).then(
              res => {
                const code = res.code;
                if (code === 200) {
                  this.$message({
                    type: "success",
                    message: "操作成功!"
                  });
                  // 刷新页面
                  this.$store.dispatch("loadPageData", this.$route.params.uri);
                } else {
                  this.$message.error(m(res.message));
                }
              },
              error => {
                console.log(error);
              }
            );
          })
          .catch(() => {});
      }
    }
  }
};
</script>
